<!DOCTYPE html>
<html lang="en">

<head>
    <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
    <title>Document</title>
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <link rel="stylesheet" href="assets/mui/css/mui.min.css">
    <link rel="stylesheet" href="assets/mui/css/iconfont.css">
    <link rel="stylesheet" href="assets/fontAwesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="css/base.css">
    <link rel="stylesheet" href="css/search.css">
    <script src="assets/zepto/zepto.min.js"></script>
    <script src="assets/mui/js/mui.min.js"></script>
    <script src="assets/artTemplate/template-native.js"></script>
    <script src="js/common.js"></script>
    <script src="./js/search.js"></script>
</head>

<body>
    <header class="mui-bar mui-bar-nav header">
        <a href="category.html" class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
        <h1 class="mui-title">搜索中心</h1>
    </header>
    <nav class="mui-bar mui-bar-tab footer">
        <a class="mui-tab-item" href="index.html">
            <span class="mui-icon mui-icon-home"></span>
            <span class="mui-tab-label">首页</span>
        </a>
        <a class="mui-tab-item" href="category.html">
            <span class="mui-icon mui-icon-bars"></span>
            <span class="mui-tab-label">分类</span>
        </a>
        <a class="mui-tab-item" href="cart.html">
            <span class="mui-icon iconfont icon-gouwuche"></span>
            <span class="mui-tab-label">购物车</span>
        </a>
        <a class="mui-tab-item" href="user.html">
            <span class="mui-icon mui-icon-person"></span>
            <span class="mui-tab-label">会员中心</span>
        </a>
    </nav>
    <div class="mui-content">
        <div class="container">
            <!-- 搜索框  开始 -->
            <div class="search">
                <input type="text" placeholder="搜索你喜欢的商品" class="text">
                <input type="button" value="搜索" class="btn">
            </div>
            <!-- 搜索框  结束 -->
            <!-- 历史记录  开始 -->
            <div class="history-top mui-clearfix">
                <!-- 搜索历史 开始 -->
                <span class="title mui-pull-left">搜索历史</span>
                <!-- 搜索历史  结束 -->
                <!-- 清空历史 开始 -->
                <span class="clear mui-pull-right mui-icon mui-icon-trash">清空历史</span>
                <!-- 清空历史  结束 -->
            </div>
            <ul class="mui-table-view" id="history">

            </ul>
            <!-- 历史记录  结束 -->
        </div>
    </div>
    <script id="search-h" type="text/template">
        <% for(var i=0;i<result.length;i++){ %>
            <li class="mui-table-view-cell">
                <%=result[i]%>
            </li>
            <%}%>
    </script>
    <script type="text/javascript" language=JavaScript charset="UTF-8">
        document.onkeydown = function(event) {
            var e = event || window.event || arguments.callee.caller.arguments[0];
            if (e && e.keyCode == 13) { // 按 Esc 
                //要做的事情

                if (localStorage.getItem('keyArr')) {
                    var arr = JSON.parse(localStorage.getItem('keyArr'));
                    arr = arr.filter(function(item, index, arr) {
                        // 遍历时候使用数组里面的值的索引来判断
                        //arr对应的数组
                        //item 数组里面对应的值
                        //index 索引值
                        return arr.indexOf(item) == index;
                    });

                    // console.log(arr);

                    arr.push(e.target.value);
                    localStorage.setItem('keyArr', JSON.stringify(arr));
                } else {
                    var arr1 = [];
                    arr1.push(e.target.value);
                    localStorage.setItem('keyArr', JSON.stringify(arr1));
                }

                window.location.href = "search-list.html";
            }
        };
        var str = $('.text').val();
        // alert(str);
        $('.text').val('');
    </script>
</body>

</html>